home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / samedat1.zip / SAMEDAT1.ASM < prev    next >
Assembly Source File  |  1992-10-18  |  4KB  |  190 lines

  1. ;v1.1 Rewrite of a utility found on SIMTEL20.
  2. ;Original was obviously written in C, and was full of
  3. ;horribly inefficient code and unused functions produced
  4. ;by a thoroughly braindead C compiler.
  5.  
  6. ;This version, while equally trivial, is at least efficient.
  7. ;
  8. ;Released to the public domain.
  9. ;David Kirschbaum
  10. ;Toad Hall
  11. ;kirsch@sesi.com
  12.  
  13.  
  14. CR    equ    0dh
  15. LF    equ    0ah
  16. SPACE    equ    32
  17. TAB    equ    9
  18.  
  19. CSEG    SEGMENT PUBLIC PARA 'CODE'
  20.     ASSUME    CS:CSEG,DS:CSEG,ES:CSEG
  21.  
  22.     ORG    100H
  23.  
  24. SameDate    PROC    NEAR
  25.     jmp    Start                ;skip over data
  26.  
  27. logo    db    'SAMEDATE -- $'        ;we use this a lot
  28.  
  29. logo1    db    'V1.1 Public Domain Utility',CR,LF
  30.     db    'David Kirschbaum, Toad Hall',CR,LF,'$'
  31.  
  32. msg1    db    'successful completion$'
  33.  
  34. msg2    db 'call error, calling sequence is:',CR,LF,CR,LF
  35.     db '       SAMEDATE file1 file2',CR,LF,CR,LF
  36.     db 'Action is to give file2 the same date as file1',CR,LF
  37.     db '   plus 1 minute.',CR,LF,'$'
  38.  
  39. msg3    db 'unable to open first file',CR,LF,'$'
  40. msg4    db 'unable to open second file',CR,LF,'$'
  41. msg5    db 'unable to read date from first file',CR,LF,'$'
  42. msg6    db 'unable to set date for second file',CR,LF,'$'
  43.  
  44. cmd_ptr    dw    81h            ;address of first byte of command tail
  45. ftime    dw    0            ;first file's time
  46. fdate    dw    0            ;first file's date
  47.  
  48. Start:    mov    dx,offset logo1        ;logo
  49.     call    WriteMsg        ;display
  50.  
  51. ;Do something horrible, just to scandalize the readers.
  52.  
  53.     mov    ax,offset Msg_Term    ;where we'll always end
  54.     push    ax
  55.  
  56.     call    Get_Arg            ;get first cmdline parm
  57.     jnc    Got_1            ;got one
  58.  
  59. CmdErr:    mov    dx,offset msg2        ;'Call error..'
  60.     mov    al,0BH            ;invalid format error
  61.     ret                ;display, terminate
  62.  
  63. Got_1:    mov    ax,3D00H        ;open file, read-only
  64.     int    21H            ;DX -> AsciiZ filename
  65.     jb    OpenFail_1        ;failed, msg, die
  66.  
  67.     mov    bx,ax            ;handle into BX
  68.     mov    ax,5700h        ;get file date/time
  69.     int    21h
  70.     jb    DateFail_1        ;failed, msg, die
  71.  
  72.     mov    ftime,cx        ;save file time
  73.     mov    fdate,dx        ;and file date
  74.  
  75.     mov    ah,3EH            ;close file
  76.     int    21h
  77.  
  78.     call    Get_Arg            ;get second cmdline parm
  79.     jb    CmdErr            ;no got:  error msg, die
  80.  
  81.     mov    ax,3D02H        ;open file, read/write
  82.     int    21H            ;DX -> AsciiZ filename
  83.     jb    OpenFail_2        ;failed, msg, die
  84.  
  85.     mov    bx,ax            ;handle into BX
  86.     mov    cx,ftime        ;first file's time
  87.     add    cx,1Eh            ;add one second
  88.     mov    dx,fdate        ;first file's date
  89.     mov    ax,5701h        ;set file date/time
  90.     int    21h
  91.     jb    DateFail_2        ;failed, msg, die
  92.  
  93.     mov    ah,3EH            ;close file
  94.     int    21h            ;(handle still in BX)
  95.  
  96.     mov    dx,offset msg1        ;'Successful completion'
  97.  
  98. ;Common way to display msg and terminate
  99. Msg_Term:
  100.     push    ax            ;save ERRORLEVEL in AL
  101.     call    WriteMsg        ;display string in DX
  102.     pop    ax            ;restore
  103.  
  104.     mov    ah,4CH            ;terminate
  105.     int    21H
  106.  
  107.  
  108. OpenFail_1:
  109.     mov    dx,offset msg3        ;'Unable to open first file
  110.     ret                ;to Msg_Term
  111.  
  112. OpenFail_2:
  113.     mov    dx,offset msg4        ;'Unable to open second file'
  114.     ret
  115.  
  116. ;Unable to read first file's date
  117. DateFail_1:
  118.     mov    dx,offset msg5        ;'Unable to read date from 1st file
  119.     ret
  120.  
  121. ;Failed to set second file's date
  122. DateFail_2:
  123.     mov    dx,offset msg6        ;'Unable to set date for second file'
  124.     ret
  125.  
  126. SameDate    ENDP
  127.  
  128.  
  129. WriteMsg    PROC    NEAR
  130.  
  131.     push    dx            ;save msg
  132.     mov    dx,offset logo        ;'SAMEDATE -- '
  133.     mov    ah,9            ;display msg
  134.     int    21H
  135.     pop    dx            ;restore original msg
  136.     mov    ah,9            ;display msg
  137.     int    21H
  138.     ret
  139. WriteMsg    ENDP
  140.  
  141.  
  142. ;* Get_Arg - Returns the address of the next command line argument in DX.
  143. ;* The argument is in the form of an ASCIIZ string.
  144. ;* Returns Carry = 1 if no more command line arguments.
  145. ;* Upon exit, if Carry is set, the contents of DX is undefined.
  146.  
  147. Get_Arg    PROC    NEAR
  148.     mov    si,cmd_ptr        ;last cmdline position
  149. skip_space:                ;scan over leading spaces and commas
  150.     lodsb
  151.     or    al,al            ;if we get a null
  152.     jz    sk0
  153.     cmp    al,CR            ;or a CR,
  154.     jnz    sk1
  155. sk0:    stc                ;set carry to indicate failure
  156.     ret                ;and exit
  157.  
  158. sk1:    cmp    al,SPACE
  159.     jz    skip_space        ;loop until no more spaces
  160.     cmp    al,','
  161.     jz    skip_space        ;or commas
  162.     cmp    al,TAB
  163.     jz    skip_space        ;or tabs
  164.  
  165.     mov    dx,si            ;start of argument
  166.     dec    dx
  167. Get_Arg1:
  168.     lodsb                ;get next character
  169.     cmp    al,CR            ;argument seperators are CR,
  170.     jz    Get_Arg2
  171.     cmp    al,SPACE        ;space,
  172.     jz    Get_Arg2
  173.     cmp    al,','            ;comma,
  174.     jz    Get_Arg2
  175.     cmp    al,TAB            ;and tab
  176.     jnz    Get_Arg1
  177.  
  178. Get_Arg2:
  179.     mov    byte ptr [si-1],0    ;delimit argument with 0
  180.     cmp    al,CR            ;if char is CR then we've reached
  181.     jnz    ga2            ; the end of the argument list
  182.      dec    si
  183. ga2:    mov    cmd_ptr,si        ;save for next time 'round
  184.     ret                ;and return
  185. Get_Arg    ENDP
  186.  
  187.  
  188. CSEG    ENDS
  189.     END    SameDate
  190.